from basics.Base import Login
from basics.assert_basics import check_all_key
from basics.parser_files import parse_json


class UserGoods(Login):

    def user_goods_pages(self, goods_name=None):
        data = {
            "url": "/api/shop/goods/pages",
            "method": "GET",
            "headers": {'Content-Type': 'application/json', 'token': self.user_token},
            "params": {
                'goods_category': '',
                'page': '1',
                'limit': '10',
                'keyword': goods_name,
                'coupon_id': '',
                'order': '',
                'sort': '',
            }
        }
        return self.send_request(self.user_goods_pages.__name__, data).json()


    def user_goods_cart(self, goods_id=None,sku_id=None,number=None):
        data = {
            "url": "/api/shop/cart",
            "method": "POST",
            "headers": {'Content-Type': 'application/json', 'token': self.user_token},
            "params": {
                        'id': '',
                        'goods_id': goods_id,
                        'sku_id':sku_id,
                        'num': number,
                    }
        }
        return self.send_request(self.user_goods_cart.__name__, data).json()

    def assert_goods_pages_check_all_key(self):
        old_data = parse_json(str(self.path.good_list_json_path))
        new_data = self.user_goods_pages()["data"]["data"][0]
        return check_all_key(old_data, new_data)

if __name__ == '__main__':
    A=UserGoods()
    print(A.user_goods_pages("林娜oh~yeah~_auto"))
# goods_id = .json()["data"]["data"][0]["goods_id"]
# sku.id = .json()["data"]["data"][0]['goodsSku']['sku_id']